package  com.game.roomlist.room
{
	public class RoomInfo
	{
	    public var uids:Array;
	    public var sids:Array;
	    public var status:Array;
	    public var icons:Array;
	    public var names:Array;
	    
    	private static var STATUS_READY:int=1;
    	private static var STATUS_ABORT:int=0;
    	
    	public var creater:int;
    	
		public function RoomInfo()
		{
			this.uids=new Array;
			this.sids=new Array;
			this.status=new Array;
			this.icons=new Array;
			this.names = new Array;
		}
		public function initRoom(uid:Array,sid:Array,sta:Array,icon:Array,creater:int,names:Array){
			for(var i in uid){
				this.uids.push(uid[i]);
				this.sids.push(sid[i]);
				this.status.push(sta[i]);
				this.icons.push(icon[i]);
				this.names.push(names[i]);
			}
			
			this.creater = creater;
		}
		public function userIn(uid:int,sid:int,icon:String,isCreater:Boolean,name:String){
			if(isCreater){
				this.creater = uid;
			}
			uids.push(uid);
			sids.push(sid);
			status.push(STATUS_ABORT);
			icons.push(icon);
			names.push(name);
		}
 		public function userOut(uid:int,creater:int){
 			this.creater = creater;
 			
			var idx:int=uids.indexOf(uid);
			uids[idx]=uids[uids.length-1];
			uids.pop();
			sids[idx]=sids[sids.length-1];
			sids.pop();
			status[idx]=status[status.length-1];
			status.pop();
			icons[idx]=icons[icons.length-1];
			icons.pop();
			
			names[idx]=names[names.length-1];
			names.pop();
		}  
		public function clear():void{
			this.uids= null;
			this.sids= null;
			this.status= null;
			this.icons= null;
			this.names = null;
						
			this.uids=new Array;
			this.sids=new Array;
			this.status=new Array;
			this.icons=new Array;
			this.names = new Array;
			
		}  
		public function size():int{
			return uids.length;
		}  
		public function getSeatid(uid:int):int{
			var idx:int=uids.indexOf(uid);
			return sids[idx];
		} 
		public function getIcon(uid:int):String{
			var idx:int=uids.indexOf(uid);
			return icons[idx];
		} 

		public function getName(uid:int):String{
			var idx:int=uids.indexOf(uid);
			return names[idx];
		} 
				
		public function userIsReady(uid:int):Boolean{
			var idx:int=uids.indexOf(uid);
			if(status[idx]==STATUS_READY){
				return true;
			}
			return false;
		}
		public function userChangeSeat(uid:int,newsid:int):void{
			var idx:int=uids.indexOf(uid);
			sids[idx]=newsid;
		}
 
	}
}